<template>
    <section class="budget-schedule">
        <el-form ref="budgetSchedule" :model="budgetSchedule" :rules="rules" label-position="right" label-width="115px">
            <el-form-item label="单日预算" prop="budgetLimit">
                <el-row>
                    <el-form-item prop="budgetLimit" style="display: inline-block">
                        <el-input class="prepandSign" v-model.number="budgetSchedule.budgetLimit" @blur="budgetBlur" ></el-input>
                    </el-form-item>
                </el-row>
            </el-form-item>
            <el-form-item label="排期" prop="date">
                <el-date-picker @change="handleDateChange" :picker-options="startDateOptions"
                                v-model="budgetSchedule.date" type="daterange">
                </el-date-picker>
                <span class="form-item-tip">&nbsp;&nbsp;（北京时间）</span>

            </el-form-item>
            <el-form-item label="竞价金额：">
                <div>
                    <el-button-group class="switch-btn-group">
                        <el-button @click="budgetSchedule.bidAmount = true" :class="{'switch-avtive': budgetSchedule.bidAmount}">自动</el-button>
                        <el-button @click="budgetSchedule.bidAmount = false" :class="{'switch-avtive': !budgetSchedule.bidAmount}">手动</el-button>
                    </el-button-group>
                    <span v-show="budgetSchedule.bidAmount" class="form-item-tip bidAmount-tip">&nbsp;&nbsp;让平台为你设置竞价，以最优价格获得最多成效</span>
                </div>
                <div v-if="!budgetSchedule.bidAmount">
                    <el-form-item class="click-cost-wraper" prop="clickCost"
                                  :rules="[{required: true, message: '请输入金额'}]">
                        <span class="click-cost-label"> CPC：每次点击最高出价&nbsp;&nbsp;</span>
                        <el-input class="click-cost prepandSign" v-model.number="budgetSchedule.clickCost" @blur="clickCostBlur" ></el-input>
                    </el-form-item>
                </div>

            </el-form-item>
            <div class="advance-setting">
                <div class="bs-title"><span class="label">高级设置：</span><el-switch v-model="showMoreSetting" on-text="" off-text="" ></el-switch></div>
                <div v-show="showMoreSetting" class="bs-container">
                    <el-form-item label="投放时间：">
                        <div>
                            <el-button-group class="switch-btn-group">
                                <el-button @click="budgetSchedule.publishTime = true" :class="{'switch-avtive': budgetSchedule.publishTime}">全天投放广告</el-button>
                                <el-button @click="budgetSchedule.publishTime = false" :class="{'switch-avtive': !budgetSchedule.publishTime}">分时段投放</el-button>
                            </el-button-group>
                        </div>
                        <div v-show="!budgetSchedule.publishTime" class="time-division-wraper">
                            <div class="td-hours">
                                <ul>
                                    <li>00</li>
                                    <li>03</li>
                                    <li>06</li>
                                    <li>09</li>
                                    <li>12</li>
                                    <li>15</li>
                                    <li>18</li>
                                    <li>21</li>
                                </ul>
                            </div>
                            <div class="td-weekDay">
                                <ul>
                                    <li>星期一</li>
                                    <li>星期二</li>
                                    <li>星期三</li>
                                    <li>星期四</li>
                                    <li>星期五</li>
                                    <li>星期六</li>
                                    <li>星期日</li>
                                </ul>
                            </div>
                            <div class="td-container">
                                <div v-for="item in timeDivision" :key="item.id" class="td-cell" @click="handleSelect(item)" :class="{active: item.selected}"></div>
                            </div>
                            <div class="td-everyday">
                                <span class="td-everyday-label">每天</span>
                                <div class="td-everyday-con">
                                    <div v-for="item in allDayHour" :key="item.id" class="td-cell" @click="selectedAllTheSameHour(item)" :class="{active: item.selected}"></div>
                                </div>
                            </div>
                            <div class="td-tips">
                                <div><span class="td-tips-icon"></span> 已排期时段</div>
                                <div style="color: #999">分时间段投放：将会按照<span class="color-red">上海时区</span>展示广告</div>
                            </div>
                        </div>
                    </el-form-item>
                </div>
            </div>
            <el-form-item label="广告组名称" prop="adsName">
                <el-input v-model="budgetSchedule.adsName" @input="handleStringLen(budgetSchedule.adsName,50)" :maxlength="adsNameLength" class="lengthLimit bs-adsprefix"></el-input><span class="stringCount">{{budgetSchedule.adsName | returnLen}}</span>
            </el-form-item>
            <el-form-item  v-if="type == 'new'"  label="">
                <el-button @click="nextStep" class="bd-next-btn" type="primary">下一步</el-button>
            </el-form-item>

            <el-form-item  v-if="type == 'edit'" label="" style="padding-top:10px;">
                <!-- <nuxt-link :to="{ path: '/manager/facebook/ads-group', query: { }}"> -->
                    <div @click="goBack" class="btn_common_grey" style="line-height:18px;margin-right:15px;">取消</div>
                <!-- </nuxt-link> -->
                <div @click="editAdGroup" class="btn_common_yellow" style="line-height:18px;">保存</div>
            </el-form-item>

        </el-form>
        <loading :customClass="createLoading" v-show="showLoading" />
    </section>
</template>

<script>
    import Vue from 'vue'
    import { Row,Col,Button,ButtonGroup,Input,Switch,Form,FormItem,Select,Option,Radio,RadioGroup,RadioButton,DatePicker,TimePicker,Message } from 'element-ui'

    Vue.use(Row)
    Vue.use(Col)
    Vue.use(Button)
    Vue.use(ButtonGroup)
    Vue.use(Switch)
    Vue.use(Input)
    Vue.use(Form)
    Vue.use(FormItem)
    Vue.use(Select)
    Vue.use(Option)
    Vue.use(Radio)
    Vue.use(RadioGroup)
    Vue.use(RadioButton)
    Vue.use(DatePicker)
    Vue.use(TimePicker)

    import ToggleButton from '~/components/toggleButton.vue'
    import { mapGetters, mapMutations} from 'vuex';
    import { getDate,toDecimal2,getRealStringLen } from '~/assets/js/global'
    import loading from '~/components/loading.vue'

    Vue.prototype.$message = Message;

    export default {
        components: {
            ToggleButton,
            loading
        },
        props:{
            'type' : {//判断是编辑还是新增new / edit
                default:'new'
            }
        },
        data () {
            return {
                showLoading: false,
                createLoading: '',
                startDateOptions: {
                    disabledDate(time) {
                        return time.getTime() < Date.now() - 8.64e7;
                    }
                },
                endDateOptions: {
                    disabledDate(time) {
                        return time.getTime() < Date.now() - 8.64e7;
                    }
                },
                budgetSchedule: {
                    /*budgetType: '单日预算',
                     schedule: '长期投放',*/
                    budgetLimit: '100.00',
                    date: [],
                    startTime: '',
                    endTime: '',
                    optimizeWays: '',
                    chargeType: '展示次数',
                    bidAmount: true,
                    clickCost: '1.00',
                    publishTime: true,
                    timeQuantumList: [],
                    adsName: ''
                },
                rules: {
                    /*budgetType: [{ required: true, message: '请选择预算类型', trigger: 'change' }],
                     schedule: [{ required: true, message: '请选择排期方式', trigger: 'blur' }],*/
                    budgetLimit: [{ required: true, message: '请输入单日预算金额'}],
                    clickCost: [{ required: true, message: '请输入手动竞价金额'}],
                    date: [{ required: true, message: '请选择排期'}],
                    adsName: [{ required: true, message: '请输入广告组名称', trigger: 'blur' }]
                },
                scheduleDays: 30,
                estimateBudget: 1900,
                showMoreSetting: false,
                timeDivision: [],
                allDayHour: [],
                selectedTD: [],
                chargetypeOption: [],
                localId: '',
                platFormId: '',
                adGroupStatus:'',
                adSeriesPlatFormId:'',
                adSeriesLocalId:'',
                editAdGroupData: null,
                adsNameLength: 50
            }
        },
        computed: {
            ...mapGetters([
                'adverPlan',
                'editAudienceForm',
                'budgetAmount',
                "adverLayout",
                "homepageList"
            ]),
            esimateData () {
                let data = {
                    "audience": {
                        "languages": this.editAudienceForm.language,
                        "keyWords": this.editAudienceForm.keywords.include,
                        "exclusedKeyWords": this.editAudienceForm.keywords.exclude,
                        "places": this.editAudienceForm.addr.include ||null
                    },
                    "budget": {
                        "isAutoBid": this.budgetSchedule.bidAmount,
                        "bidAmount": this.budgetSchedule.clickCost,
                        "budgetAmount": this.budgetSchedule.budgetLimit
                    }
                };

                return data
            }
        },
        filters: {
            returnLen(val) {
                return 50-getRealStringLen(val)
            }
        },
        methods: {
            handleStringLen(val,len) {
                let realLen = getRealStringLen(val);
                let slen = val.length;
                this.adsNameLength = len - (realLen-slen);
            },
            //自动名称
            autoAdverName(){
                let time = new Date();
                let year = (time.getFullYear()+"").substr(2,2);
                let month = (time.getMonth()+1)<10?"0"+(time.getMonth()+1):(time.getMonth()+1)+"";
                let day = time.getDate()<10?"0"+time.getDate():time.getDate()+"";
                let hour = time.getHours()<10?"0" + time.getHours() : time.getHours();
                let minu = time.getMinutes()<10?"0" + time.getMinutes() : time.getMinutes();
                this.budgetSchedule.adsName = year+month+day+hour+minu+'-广告组';
                return year+month+day+hour+minu+'-广告组';
            },
            setDefaultSchedule () {
                if(!this.budgetSchedule.date.length){
                    let d = new Date();
                    d.setDate(d.getDate());
                    this.budgetSchedule.startTime = d.getTime();
                    this.budgetSchedule.date.push(new Date(getDate(d)));
                    d.setDate(d.getDate()+30);
                    this.budgetSchedule.endTime = d.getTime();
                    this.budgetSchedule.date.push(new Date(getDate(d)))
                }
            },
            handleDateChange () {
                if(!this.budgetSchedule.date[0]) return false;
                this.budgetSchedule.startTime = this.budgetSchedule.date[0].getTime();
                this.budgetSchedule.endTime = this.budgetSchedule.date[1].getTime();
                if(this.budgetSchedule.startTime == this.budgetSchedule.endTime || this.budgetSchedule.date[1].getHours() == 0){
                    this.budgetSchedule.endTime += (23*60*60 + 59*60 + 59) * 1000;
                }
                if(this.type == 'edit') {
                    /*if(this.budgetSchedule.date[0].getDate() != new Date(this.editAdGroupData.budgetScheduling.startTime).getDate()) {
                        this.$message({
                            type: 'warning',
                            message: '编辑广告组时排期的开始时间不可修改！'
                        });
                    }*/
                    this.budgetSchedule.startTime = this.editAdGroupData.budgetScheduling.startTime;
                    this.budgetSchedule.date = [new Date(this.editAdGroupData.budgetScheduling.startTime),this.budgetSchedule.date[1]]
                }
            },
            //初始化时间段表格
            initTimeDivision () {
                //周一~周日
                for (let i=1;i<7;i++) {
                    for (let j=0;j<24;j++) {
                        let item = {};
                        item.selected = false;
                        item.day = i;
                        item.hour = j;
                        this.timeDivision.push(item)
                    }
                }
                //周日为：0
                for (let i=0;i<1;i++) {
                    for (let j=0;j<24;j++) {
                        let item = {};
                        item.selected = false;
                        item.day = i;
                        item.hour = j;
                        this.timeDivision.push(item)
                    }
                }
                //全选表格
                for (let k=0;k<24;k++) {
                    let item = {day: 0,selected: false,selectNum:0};
                    item.hour = k;
                    this.allDayHour.push(item);
                    this.budgetSchedule.timeQuantumList.push({
                        "start": k*60,
                        "end": k*60+60,
                        "days": []
                    })
                }
            },
            //全选事件
            selectedAllTheSameHour (item) {
                item.selected = !item.selected;
                for (let i=0;i<7*24;i++) {
                    if(this.timeDivision[i].hour === item.hour){
                        this.timeDivision[i].selected = item.selected
                    }
                }
                item.selectNum = item.selected ? 7 : 0;
                this.budgetSchedule.timeQuantumList[item.hour].days = item.selected ? [0,1,2,3,4,5,6] : []
            },
            //单选事件
            handleSelect (item) {
                item.selected = !item.selected;
                let a = this.allDayHour[item.hour].selectNum;
                this.allDayHour[item.hour].selectNum = item.selected ? a + 1 : a - 1;
                if (this.allDayHour[item.hour].selectNum === 7) {
                    this.allDayHour[item.hour].selected = true
                }
                else {
                    this.allDayHour[item.hour].selected = false
                }

                if (item.selected) {
                    this.budgetSchedule.timeQuantumList[item.hour].days.push(item.day)
                }else {
                    let arr = this.budgetSchedule.timeQuantumList[item.hour].days;
                    let len =  arr.length;
                    for(let i=0;i<len;i++) {
                        if(arr[i] == item.day){
                            this.budgetSchedule.timeQuantumList[item.hour].days.splice(i,1);
                            break;
                        }
                    }
                }
            },
            clickCostBlur() {
                if(isNaN(this.budgetSchedule.clickCost)){
                    this.budgetSchedule.clickCost = '1.00';
                    this.$message({
                        type: 'warning',
                        message: '请输入正确的数字金额'
                    });
                    return false
                }else if(this.budgetSchedule.clickCost <= 0) {
                    this.budgetSchedule.clickCost = '1.00';
                    this.$message({
                        type: 'warning',
                        message: '出价金额必须大于￥0.00'
                    });
                    return false
                }else {
                    this.budgetSchedule.clickCost = toDecimal2(this.budgetSchedule.clickCost);
                }
                this.$store.commit('STEP_CLICKCOST',{data: '￥' + this.budgetSchedule.clickCost});
                this.handleEsimate()
            },
            budgetBlur() {
                if(isNaN(this.budgetSchedule.budgetLimit)){
                    this.budgetSchedule.budgetLimit = '100.00';
                    this.$message({
                        type: 'warning',
                        message: '请输入正确的数字金额'
                    });
                }else if(this.budgetSchedule.budgetLimit <= 0) {
                    this.budgetSchedule.budgetLimit = '100.00';
                    this.$message({
                        type: 'warning',
                        message: '单日预算金额必须大于￥0.00'
                    });
                }else {
                    this.budgetSchedule.budgetLimit = toDecimal2(this.budgetSchedule.budgetLimit);
                }
                this.$store.commit('STEP_BUDGET',{data: this.budgetSchedule.budgetLimit});
                this.handleEsimate()
            },
            switchOptimizeWays () {
                let optimizeWays = [];
                switch(this.adverPlan){
                    case '访问量': optimizeWays = ["网站链接点击量","展示次数","单日独立覆盖"];
                        break;
                    case '品牌知名度': optimizeWays = ["覆盖人数","品牌知名度"];
                        break;
                    case '主页赞': optimizeWays = ["主页赞"];
                        break;
                }
                if(this.budgetSchedule.optimizeWays == ''){
                    this.budgetSchedule.optimizeWays = optimizeWays[0];
                    this.changeOptimizeWays()
                }
                //return optimizeWays
            },
            changeOptimizeWays(){
                switch(this.budgetSchedule.optimizeWays){
                    case '网站链接点击量': this.chargetypeOption = ["展示次数","链接点击量"];
                        break;
                    case '展示次数': this.chargetypeOption = ["展示次数"];
                        break;
                    case '单日独立覆盖': this.chargetypeOption = ["展示次数"];
                        break;
                    case '覆盖人数': this.chargetypeOption = ["展示次数"];
                        break;
                    case '品牌知名度': this.chargetypeOption = ["展示次数"];
                        break;
                    case '主页赞': this.chargetypeOption = ["展示次数","主页赞"];
                        break;
                }
                this.budgetSchedule.chargeType = this.chargetypeOption[0]
            },
            handleTimeShare(){
                if(!this.budgetSchedule.budgetType){
                    this.$message({
                        type: 'warning',
                        message: '请先选择单广告预算'
                    })
                }
                else if(this.budgetSchedule.budgetType === '总预算') {
                    this.budgetSchedule.publishTime = false
                }
                else {
                    this.$message({
                        type: 'warning',
                        message: '只有单广告预算为总预算才可以选择分时段投放'
                    })
                }
            },
            removeEmptyTime() {
                let tLen = this.budgetSchedule.timeQuantumList.length;
                let tArr = [];
                for (let i=0;i<tLen;i++) {
                    this.budgetSchedule.timeQuantumList[i].days.length ? tArr.push(this.budgetSchedule.timeQuantumList[i]) : false;
                }
                return tArr;
            },
            handleEsimate() {
                if(this.type == 'edit'){
                    return;
                }
                //查询预计成效
                this.$store.dispatch('getEsimate',JSON.stringify(this.esimateData))
                    .then(res => {
                        if(res && res.data) {
                            this.$store.commit('GG_ESIMATE',{data: res.data.data});
                            this.$store.commit("GGAUDIENCE_COUNT_TIPS", {item: res.data.data})
                        }
                    });
            },
            nextStep(){
                this.$refs.budgetSchedule.validate((valid) => {
                    if (valid) {
                        if(!this.budgetSchedule.publishTime && this.removeEmptyTime().length == 0){
                            this.$message({
                                type: 'warning',
                                message: '分时段投放请至少选择一个时间段'
                            })
                            return false
                        }

                        let item = [
                            {
                                created:true,//是否完成本步编辑
                                click:true,     //是否可点击
                                style:"li-created",//样式分为default/active/created
                                step:'3',
                                title:"预算和排期",
                                info:'',
                                icon:'el-icon-check'//图标分为√和>
                            }
                        ];
                        this.$store.commit('BUDGET_SCHEDULE',{data: this.budgetSchedule});
                        this.$store.commit('ADSTEP_LIST_CREATED', {item});
                        this.$store.commit('ACTIVE_STEP', {step:"4"});
                        if(!this.stepCreated){
                            this.$store.commit('CREATED_STEP', {step:"4"});
                            this.stepCreated = true;
                        }
                    } else {

                    }
                })
            },
            editAdGroup(){
                let position = {
                   devicePlatforms: ["DESKTOP","MOBILE"]
                }

                let params = {
                    localId: this.localId,
                    name: this.budgetSchedule.adsName,
                    platFormId: this.platFormId,
                    adSeriesPlatFormId: this.adSeriesPlatFormId,
                    adSeriesLocalId: this.adSeriesLocalId,
                    adGroupStatus: this.adGroupStatus,
                    // esimate: null,
                    // errorInfo: null,
                    audience:{
                        places:this.editAudienceForm.addr.include||[],
                        exclusedPlaces:this.editAudienceForm.addr.exclude||[],
                        languages: this.editAudienceForm.language,
                        keyWords: this.editAudienceForm.keywords.include,
                        exclusedKeyWords: this.editAudienceForm.keywords.exclude
                    },
                    budgetScheduling: {   //预算和排期
                        "budget": {
                            "platFormId": this.platFormId,
                            "isAutoBid": this.budgetSchedule.bidAmount,
                            "bidAmount": this.budgetSchedule.bidAmount?null:this.budgetSchedule.clickCost,
                            "budgetAmount": this.budgetSchedule.budgetLimit,   //预算
                        },
                        "scheduling": {
                            "platFormId": this.platFormId,
                            "isDailyDelivery": this.budgetSchedule.publishTime,   //是否全天投放
                            "timeQuantumList": this.budgetSchedule.publishTime?null:this.budgetSchedule.timeQuantumList,
                        },
                        "startTime": this.editAdGroupData.budgetScheduling.startTime,    //开始时间
                        "endTime": this.budgetSchedule.endTime,  //结束时间
                    },
                    
                };
                //分时段投放
                if(!this.budgetSchedule.publishTime) {
                    let tLen = this.budgetSchedule.timeQuantumList.length;
                    let tArr = [];
                    for (let i=0;i<tLen;i++) {
                        this.budgetSchedule.timeQuantumList[i].days.length ? tArr.push(this.budgetSchedule.timeQuantumList[i]) : false;
                    }
                    params.budgetScheduling.scheduling.timeQuantumList = tArr
                }

                if(!params.audience.places.length){
                    this.$message({
                        type: 'error',
                        message: '请至少选择一个位置!'
                    });
                    return;
                }
                if(!params.audience.languages.length){
                    this.$message({
                        type: 'error',
                        message: '请至少选择一个语言!'
                    });
                    return;
                }
                if(!params.audience.keyWords.length){
                    this.$message({
                        type: 'error',
                        message: '请至少选择一个关键词!'
                    });
                    return;
                }
                if(!params.name){
                    this.$message({
                        type: 'error',
                        message: '请输入广告组名称!'
                    });
                    return;
                }

                this.showLoading = true;
                let preload = JSON.stringify(params);

                this.$store.dispatch('editGgAdGroup',preload).then((res)=>{
                    this.showLoading = false;
                    if(res.data && res.data.success) {
                        this.$message({
                            type: 'success',
                            message: '修改广告组成功!'
                        });
                        this.$router.go(-1)
                    }else {
                        this.budgetSchedule.date[0] = new Date(this.editAdGroupData.budgetScheduling.startTime);
                        this.budgetSchedule.date[1] = new Date(this.editAdGroupData.budgetScheduling.endTime);
                        this.budgetSchedule.startTime = this.editAdGroupData.budgetScheduling.startTime;
                        this.budgetSchedule.endTime = this.editAdGroupData.budgetScheduling.endTime;
                    }
                })
            },

            goBack(){
                this.$router.go(-1)
            }

        },
        watch: {
            adverPlan() {
                this.budgetSchedule.optimizeWays = '';
                this.switchOptimizeWays()
            },
            'budgetSchedule.date'() {
                if(!this.budgetSchedule.date[0]) return false;
                let start = this.budgetSchedule.date[0];
                let end = this.budgetSchedule.date[1];
                let year = start.getFullYear();
                let month = (start.getMonth() + 1 < 10 ? '0' + (start.getMonth() + 1) : start.getMonth() + 1);
                let day = start.getDate() < 10 ? '0' + start.getDate() : start.getDate();
                start = year+'/'+month+'/'+day;
                year = end.getFullYear();
                month = (end.getMonth() + 1 < 10 ? '0' + (end.getMonth() + 1) : end.getMonth() + 1);
                day = end.getDate() < 10 ? '0' + end.getDate() : end.getDate();
                end = year+'/'+month+'/'+day;
                this.$store.commit('STEP_SCHEDULE',{data: start+'-'+end})
            },
            'budgetSchedule.adsName'() {
                this.$store.commit('BUDGET_SCHEDULE',{data: this.budgetSchedule});
            },
            'budgetSchedule.bidAmount'() {
                let cost = this.budgetSchedule.bidAmount ? '自动' : '￥' + this.budgetSchedule.clickCost;
                this.$store.commit('STEP_CLICKCOST',{data: cost});
            }
        },
        created () {
            this.initTimeDivision();
            this.setDefaultSchedule();
            this.autoAdverName();
        },
        mounted () {
            this.$store.commit('STEP_BUDGET',{data: this.budgetSchedule.budgetLimit});
            this.handleEsimate();
            //编辑
            if(this.type=='edit'){
                let params = {
                    localId:this.$route.query.localAdId,
                    platFormId:this.$route.query.platFormId
                };
                this.localId = this.$route.query.localAdId;
                this.platFormId = this.$route.query.platFormId;
                this.$store.dispatch('getGgAdGroupById',params).then((res)=>{
                    if(res.data && res.data.data){
                        let result = res.data.data;
                        this.editAdGroupData = result;
                        this.adGroupStatus = result.adGroupStatus;
                        this.adSeriesPlatFormId = result.adSeriesPlatFormId;
                        this.adSeriesLocalId = result.adSeriesLocalId;

                        //受众
                        let content = result.audience;
                        let budgetData = result.budgetScheduling;
                        // if(content.keyWords.length){
                        //     for (let i = 0; i<content.keyWords.length;i++) {
                        //         content.keyWords[i].platFormId = this.platFormId;
                        //     }
                        // }
                        // if(content.exclusedKeyWords.length){
                        //     for (let i = 0; i<content.exclusedKeyWords.length;i++) {
                        //         content.exclusedKeyWords[i].platFormId = this.platFormId;
                        //     }
                        // }
                        if(content){
                            this.editAudienceForm.language = content.languages || [];
                            this.editAudienceForm.keywords.include = content.keyWords || [];
                            this.editAudienceForm.keywords.exclude = content.exclusedKeyWords || [];
                            this.editAudienceForm.addr.include = content.places || [];
                            this.editAudienceForm.addr.exclude = content.exclusedPlaces || [];
                        }
                        //this.editAudienceForm.keywords.include = [{value:'han'}]
                        //预算排期
                        //this.budgetSchedule.date = [budgetData.startTime.toString(),budgetData.endTime.toString()];
                        this.budgetSchedule.date = [];
                        this.budgetSchedule.date.push(new Date(budgetData.startTime));
                        this.budgetSchedule.date.push(new Date(budgetData.endTime));
                        this.startDateOptions = {
                            disabledDate(time) {
                                return time.getTime() < budgetData.startTime - 8.64e7;
                            }
                        };

                        this.budgetSchedule.budgetLimit = budgetData.budget.budgetAmount;
                        this.budgetSchedule.bidAmount = budgetData.budget.isAutoBid;
                        this.budgetSchedule.clickCost = budgetData.budget.bidAmount;
                        this.budgetSchedule.publishTime = budgetData.scheduling.isDailyDelivery;
                        if(!budgetData.scheduling.isDailyDelivery){
                            let data = budgetData.scheduling.timeQuantumList;
                            for (let i=0;i<data.length;i++) {
                                let start = data[i].start/60;
                                let end = data[i].end/60;
                                for(start;start<end;start++) {
                                    let hour = start;
                                    let day = data[i].days[0];
                                    if(day != 0) {
                                        this.handleSelect(this.timeDivision[(day-1)*24+hour])
                                    } else {
                                        this.handleSelect(this.timeDivision[6*24+hour])
                                    }
                                }
                            }
                        }
                        this.budgetSchedule.adsName = result.name || this.autoAdverName();
                        
                    }
                })
            }

        }
    }
</script>

<style lang="scss" >
    .budget-schedule{

    }


</style>